<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <style type="text/css">
      * {
        margin: 0;
        padding: 0;
      }
      button {
        padding: 2px 6px;
      }
      input {
        padding: 2px;
        margin: 0px -3px;
        outline: none;
      }
    </style>
    <button onclick="minus()">-</button>
    <input type="text" id="in" placeholder="0" />
    <button onclick="add()">+</button>
    <script>
      function minus() {
        var a = document.getElementById("in");
        if (a.placeholder > 0) a.placeholder = parseInt(a.placeholder) - 1;
        else alert("不能再少了！");
      }
      function add() {
        var a = document.getElementById("in");
        a.placeholder = parseInt(a.placeholder) + 1;
      }
    </script>
  </body>
</html>
